{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ch9.4 k_means\n",
    "试编程实现 K 均值算法设置三组不同的K值、三组不同初始中心点，在西瓜数据集4.0上进行实验比较，并讨论什么样的初始中心有利于取得好结果。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "dataset = pd.read_csv('data/table_9_1_watermelon_4_0.csv')\n",
    "dataset = dataset.drop(['Idx'], axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def get_nearest_dist_num(x_j, u):\n",
    "    dist = np.zeros(len(u))\n",
    "    for i in range(len(u)):\n",
    "        dist[i] = np.sum((x_j-u[i])**2)\n",
    "    return np.argmin(dist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "def k_means(dataset, k=3):\n",
    "    random_int = np.random.randint(0,len(dataset),size=k)\n",
    "    while len(np.unique(random_int)) < k:\n",
    "        random_int = np.random.randint(0,len(dataset),size=k)\n",
    "    count = 0\n",
    "    u = np.zeros([k, 2])\n",
    "    print('k-means: k=',end=\"\")\n",
    "    print(k)\n",
    "    for i in range(k):\n",
    "        u[i] = list(dataset.ix[random_int[i],:-1])\n",
    "    print(u)\n",
    "\n",
    "    for t in [221,222,223,224]:\n",
    "        C = dict()\n",
    "        for i in range(k):\n",
    "            C[i] = []\n",
    "        for j in range(len(dataset)):\n",
    "            lambda_j = get_nearest_dist_num(np.array(dataset.ix[j,:-1]), u)\n",
    "            C[lambda_j].append(list(dataset.ix[j,:-1]))\n",
    "        for i in range(k):\n",
    "            u[i] = np.mean(C[i], axis=0)\n",
    "\n",
    "        dataset0 = dataset[dataset['label']==0]\n",
    "        dataset1 = dataset[dataset['label']==1]\n",
    "        color = ['g', 'b', 'r']\n",
    "        fig = plt.subplot(t)\n",
    "        for i in range(k):\n",
    "            fig.plot(np.array(C[i])[:,0], np.array(C[i])[:,1], color[i]+'.')\n",
    "            fig.plot(u[i,0],u[i,1], color[i]+'+')\n",
    "\n",
    "        plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "k-means: k=2\n",
      "[[ 0.725  0.445]\n",
      " [ 0.774  0.376]]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAACFCAYAAADrYDycAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACYJJREFUeJzt3V+IXGcZx/Hv45YBxaLirl6kCRvFf/HfhdvKgNCpuTDt\nTSnkQisGixAqtHiZ1gszy15se1dBTQmhBK9y01JUolVWpgacohtobKO0xDR1Uy+aVkHpzbKbx4uZ\n3QzHndmzZ84573vO+X1g2JnZM2fed2ae8/497zF3R0RueV/oBIjERkEhkqCgEElQUIgkKChEEhQU\nIgkKCpEEBYVIgoJCJOG2UG88Ozvr8/Pzod5eau7ixYvvuPtcltcGC4r5+XlWV1dDvb3UnJm9mfW1\nqj5J1PprfZYvLNNf65f2nsFKCpHd9Nf6HP75YdY312nNtFg5tkJ7f7vw91VJIdHqXeuxvrnOpm+y\nvrlO71qvlPdVUEi0OvMdWjMtZmyG1kyLznynlPdV9anC+mt9etd6dOY7pVQrytbe32bl2ErpeVRQ\nVFSo+nbZ2vvbpedL1acSFNGDEqq+nVWIXqSsVFIUrKgj+lZ9e2u/ZdW3s6haqaaSomBFHdG36ttL\n9yxF/yOrWqmmkqJgRR7RQ9S3s0jzGcTUaWChVvNYWFjwpkzziOkLD2XSZ1BE9cr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gGHxmz3e+A8cDR0uqfJD/Bh4K/AgeHjj4VO95T5\n+SHw5PD+HPAvoDVpvyopJrsLuOLuV919HTgH3L/Ddo8CzwJvl5m4DNLk50HgOXf/B4C7x5ynNPlx\n4HYzM+CDDIJiY9JOFRST7QPWRh5fHz63zcz2AQ8Ap0pMV1a75gf4NPARM+uZ2UUzO1Za6vYuTX5+\nAnwO+CfwCvADd785aaeaJTu9p4AT7n5zcDCqvNuArwCHgfcDfTN7yd1fD5uszL4BvAx8Hfgk8Dsz\nu+Du/xn3AgXFZG8B+0ce3zF8btQCcG4YELPAfWa24e7Pl5PEPUmTn+vAu+7+HvCemf0B+DIQY1Ck\nyc9DwBM+aFRcMbM3gM8Cfxq719CNpZhvDA4aV4GD3GrIfX7C9meJu6G9a34YVDVWhtt+AHgV+ELo\ntE+Rn1NAd3j/48OgmZ20X5UUE7j7hpk9ArzAoKfjGXe/bGYPD///dNAE7lGa/Lj738zsN8BfgJvA\nGXd/NVyqx0v5/SwBZ83sFcAYVHUnTpHXNA+RBPU+iSQoKEQSFBQiCQoKkQQFhUiCgkIkQUEhkvA/\nbK/oF1vvI4QAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x75edb00>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAACFCAYAAADrYDycAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACaJJREFUeJzt3V+IXGcZx/Hv45YFxaLiRi/SDRvFf/HfhdvKgpKpe2Ha\nm1LIhVYsLUKo0OJlWqHuhL3Y9q6CmhJCCb3KTUtRiVZZnRpwim6gsY3SEtPUTb1oWgWlN8tuHi9m\nNllPd2bOnDnnvO855/eBJTuzZ868ZzLPef895z3m7ojIDe8LXQCR2CgoRBIUFCIJCgqRBAWFSIKC\nQiRBQSGSoKAQSVBQiCTcFOqNZ2ZmfG5uLtTbS82dO3fub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jQ0KyVeMZ/ysNE8hkhBlUHTXu6ycXWnsbbMkrOiaT5pDkNCiqym0\nWp+EFl1QhFzCvmlizDuKQXTNJ80hlCPWvKMYRBcUoDmEMsSadxSD6JpPUg4tljBYlDWFFK9us9B5\nUlA0WJ1mofOk5pNIQrD7U5jZVeCNIG+ejxng7dCFyFHdjucz7n5zlhcGaz65+55Q750HM1ur0t2a\nRqnj8WR9rZpPIgkKCpEEBUV2J0IXIGc6nr5gHW2RWKmmEElQUIgkKChGMLNDZvaqmV00s4eHbHer\nmW2a2eEyyzeuNMdjZi0ze8nMLpjZC2WXcRyjjsfMPmRmvzCz8/3juX/kTt1dPwN+gCng78AngGng\nPHBgwHa/A84Ah0OXe5LjAT4M/BXY13/8sdDlnvB4fgg83v99D/AvYHrYflVTDHcbcNHdL7n7BnAa\nuGuX7R4CngHeKrNwGaQ5nnuAZ939HwDuHvMxpTkeB242MwM+SC8oNoftVEEx3F5gfcfjK/3nrjOz\nvcDdwPESy5XVyOMBPg18xMw6ZnbOzO4trXTjS3M8PwE+B/wTeBn4gbtfG7ZTZclO7gngqLtf652M\nKu8m4CvAIvB+oGtmL7r7a2GLldk3gZeAbwCfBH5rZmfd/T+DXqCgGO5NYHbH41v6z+00D5zuB8QM\ncKeZbbr7c+UUcSxpjucK8I67vwu8a2Z/AL4MxBgUaY7nfuAx73UqLprZ68BngT8N3GvozlLMP/RO\nGpeA/dzoyH1+yPaniLujPfJ46DU1VvvbfgB4BfhC6LJPcDzHgXb/94/3g2Zm2H5VUwzh7ptm9iDw\nPL2Rjqfc/YKZPdD/+5NBCzimNMfj7n8zs18DfwGuASfd/ZVwpR4s5f/PMnDKzF4GjF5Td2iKvNI8\nRBI0+iSSoKAQSVBQiCQoKEQSFBQiCQoKkQQFhUjC/wDLSOH5gE8fKwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x75d7da0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/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L9ILhqX\ngf3c6Mh9fsz2Z4i7oz3xfEiaGkujbT8AvAp8IXTZpzifk0B/9PPHR0EzN26/qinGcPc1M3sIeJ5k\npONpd79oZg+O/v5U0ALuUpbzcfe/mdlvgL8A14HT7v5quFLvLOP/zyJwxsxeAYykqTs2RV5pHiIp\nGn0SSVFQiKQoKERSFBQiKQoKkRQFhUiKgkIk5X/rtL7/JgYqZwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7649710>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAACFCAYAAADrYDycAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACZ9JREFUeJzt3V+IHWcZx/Hv45YFxaLiRi/SDRvFf/HfhaeVA0pPzYVp\nb0ohF1qxtAihQouXaYWaE/Yi7V0FNSWEErzKTUtRiVZZObXgKbqBxjZKS0xTN/WiaRWU3iy7ebyY\ns5tl3D1nds7MvO/M/D6w7J7dOTPvJOeZ998z75i7IyI3vC90AURio6AQSVFQiKQoKERSFBQiKQoK\nkRQFhUiKgkIkRUEhknJTqAPPzc35wsJCqMNLw50/f/4dd9+T573BgmJhYYHl5eVQh5eGM7M3875X\nzSeJ2nAIJ04k36sSrKYQmWQ4hIMHYXUVZmdhaQm63fKPq5pCojUYJAGxvp58HwyqOa6CQqLV6yU1\nxMxM8r3Xq+a4aj7V2HBlyODKgN5Cj+58Be2KinW7SZNpMEgCooqmEygoamu4MuTgzw+yur7K7Mws\nS/ctNTYwqgqGDWo+VWC4MuTEiycYrhQ3hDK4MmB1fZV1X2d1fZXBlUFh+y5DiFGkvFRTlKysK3pv\nocfszOzmfnsLvekLW5JQo0h5qaYoWVlX9O58l6X7lli8YzH6plOoUaS8VFOUrMwrene+G3UwbNgY\nRdqoKbYbRRoOq+9Q70RBUbKNK3qTR4kmmTSKFFvzSkFRgUlX9KYPrcL4Ua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lxy98vuvgqcBe7e\nZruHgWeAt6ssXA5Zzude4Fl3/weAu8d8TlnOx4GbzcyAD5IExdq4nSooxtsLrGx5fXX0u01mthe4\nBzhZYbnymng+wKeBj5jZwMzOm9l9lZVu97Kcz0+AzwH/BF4BfuDu18ftVFmy03sSOOru15OLUe3d\nBHwFOAi8Hxia2Uvu/nrYYuX2TeBl4BvAJ4HfmdmL7v6fnd6goBjvLWB+y+tbRr/bqgOcHQXEHHCX\nma25+3PVFHFXspzPVeBdd38PeM/M/gB8GYgxKLKczwPA4550Ki6Z2RvAZ4E/7bjX0J2lmL9ILhqX\ngf3c6Mh9fsz2Z4i7oz3xfEiaGkujbT8AvAp8IXTZpzifk0B/9PPHR0EzN26/qinGcPc1M3sIeJ5k\npONpd79oZg+O/v5U0ALuUpbzcfe/mdlvgL8A14HT7v5quFLvLOP/zyJwxsxeAYykqTs2RV5pHiIp\nGn0SSVFQiKQoKERSFBQiKQoKkRQFhUiKgkIk5X/rtL7/JgYqZwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x766f470>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "k_means(dataset, k=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "k-means: k=2\n",
      "[[ 0.478  0.437]\n",
      " [ 0.525  0.369]]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAACFCAYAAADrYDycAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACbhJREFUeJzt3U1oHOcdx/HvvwqClIa2VG4Pjozc0jf3JQcrKYKCN9Wh\nTi9pwIe+UNNQMKEk9BhTSCUjkJtbDm0cTAghJx+aEFpwmxa1mwS0oZUhieMWB9VxLKeHOGmhkIuQ\n/O9hV7Yy3ZfZ2Zl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SGSoKAQSfgfBJUv\nUXPogasAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xadf06a0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAACFCAYAAADrYDycAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACZVJREFUeJzt3U9oHOcZx/HvUxmBS0NbKrcHx0Zu6T+3aQ5WUgSFbOpD\nnVxCwIc2paahYHJIyDGmkFpCBze3HNo6mBBMT74khLa4TYvKpgFtaGVI4rjFQXWcyukhTloo5CIk\nPz3MSl6G/TOanZn3nZ3fBxZpV7Mz72j3mffvvK+5OyJy2ydCJ0AkNgoKkRQFhUiKgkIkRUEhkqKg\nEElRUIikKChEUhQUIil7Qh14ZmbGZ2dnQx1eJtylS5c+dPd9ed4bLChmZ2dZXV0NdXiZcGb2Xt73\nqvgkUet04MyZ5GdVguUUIqN0OnD0KGxswPQ0LC/D/Hz5x1VOIdFqt5OA2NpKfrbb1RxXQSHRarWS\nHGJqKvnZalVzXBWfaqyz3qF9vU1rtsX8gQrKFRWbn0+KTO12EhBVFJ1AQVFbnfUOR399lI2tDaan\nplk+sTyxgVFVMGxT8akCnfUOZ147Q2e9uCaU9vU2G1sbbPkWG1sbtK+3C9t3GUK0IuWlnKJkZV3R\nW7Mtpqemd/bbmm2Nn9iShGpFyks5RcnKuqLPH5hn+cQyS/cvRV90CtWKlJdyipKVeUWfPzAfdTBs\n225F2s4p+rUidTrVV6gHUVCUbPuKPsmtRKOMakWKrXiloKjAqCv6pDetwvBWpH7FKwVFgzWlaXWY\nLMWrKqmiHVjdmlbLsF28WloKX3QC5RTB1alptUwhOukGUVAEpop4fBQUEahL02pTZKpTmNkxM7tq\nZmtmdmrIdveY2aaZHS8uiSLVGhkUZjYF/BJ4ADgM/MDMDg/Y7hngj0UnUqRKWXKKe4E1d7/m7hvA\nBeChPts9Abw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B7wBfBf4EvAnM3vN3f836A0KiuHeBw70PL+z+1qvOeBCNyBmgAfNbNPdX64mibuS\n5XxuAB+5+8fAx2b2F+BuIMagyHI+jwI/96RSsWZm7wJfA/46cK+hK0sxP0guGteAQ9yuyH1jyPbn\nibuiPfJ8SIoay91tPwm8DXwzdNrHOJ+zwEL39y90g2Zm2H6VUwzh7ptm9jjwCklLxwvufsXMHuv+\n/bmgCdylLOfj7v8wsz8AbwG3gOfd/e1wqR4s4+ezBJw3s8uAkRR1hw6R1zAPkRS1PomkKChEUhQU\nIikKCpEUBYVIioJCJEVBIZLyf94WF99rCJnuAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xadae278>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAACFCAYAAADrYDycAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACZlJREFUeJzt3V+IHWcZx/Hv45YFxaLiRi/SDRvFf/HfhdvKgtJTc2Ha\nm1LIhVYMFiFUaPEyrVBzwl6kvaugpoRQgle5aSkq0SorpxY8RTfQ2EZpiWnqpl40rYLSm2U3jxdz\ndnMY9pwzO2dm3ndmfh9Yds/unJl3kvPM+7x/5h1zd0TkpveFLoBIbBQUIikKCpEUBYVIioJCJEVB\nIZKioBBJUVCIpCgoRFJuCXXgubk5X1hYCHV4abgLFy684+578rw3WFAsLCywuroa6vDScGb2Zt73\nKn2SqPX7cPJk8r0qwWoKkUn6fTh4ENbXYXYWVlZgaan846qmkGj1eklAbG4m33u9ao6roJBodTpJ\nDTEzk3zvdKo5rtKnGuuv9eld7dFZ6LA0X0FeUbGlpSRl6vWSgKgidQIFRW311/oc/MVB1jfXmZ2Z\nZeXISmMDo6pg2KL0qQL9tT4nXzxJf624LpTe1R7rm+ts+ibrm+v0rvYK23cZQvQi5aWaomRlXdE7\nCx1mZ2a399tZ6Exf2JKE6kX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Wqy7gbk87HzD5kZr8ys4uD83lg4k7dXV8jvoAZ4B/AJ4BZ4CJwYMR2fwDO\nA4dDl3ua8wE+DPwN2Dd4/bHQ5Z7yfH4EPDH4eQ/wb2B23H5VU4x3B3DZ3a+4+zpwDrh3h+0eBp4B\n3q6ycDlkOZ/7gWfd/Z8A7h7zOWU5HwduNTMDPkgSFBvjdqqgGG8vsDb0+trgd9vMbC9wH3CqwnLl\nNfF8gE8DHzGznpldMLMjlZVu97Kcz0+BzwH/Al4BfujuN8btVLNkp/ckcMzdbyQXo9q7BfgKcBB4\nP9A3s5fc/fWwxcrtm8DLwDeATwK/N7MX3f2/o96goBjvLWB+6PVtg98NWwTODQJiDrjHzDbc/blq\nirgrWc7nGvCuu78HvGdmfwS+DMQYFFnO5wHgcU8aFZfN7A3gs8CfR+41dGMp5i+Si8YVYD83G3Kf\nH7P9WeJuaE88H5JUY2Ww7QeAV4EvhC77FOdzCugOfv74IGjmxu1XNcUY7r5hZg8Bz5P0dDzt7pfM\n7MHB358KWsBdynI+7v53M/st8FfgBnDG3V8NV+rRMv7/LANnzewVwEhS3bFT5DXNQyRFvU8iKQoK\nkRQFhUiKgkIkRUEhkqKgEElRUIik/B+ocqc6CnzjAAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0xae5de80>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMUAAACFCAYAAADrYDycAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACZ9JREFUeJzt3V+IHWcZx/Hv45YFxaLiRi/SDRvFf/HfhaeVA0pPzYVp\nb0ohF1qxtAihQouXaYWaE/Yi7V0FNSWEErzKTUtRiVZZObXgKbqBxjZKS0xTN/WiaRWU3iy7ebyY\ns5tl3D1nds7MvO/M/D6w7J7dOTPvJOeZ998z75i7IyI3vC90AURio6AQSVFQiKQoKERSFBQiKQoK\nkR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DAjSDXKRYr/h5tTYopFgxXvHz0jyFSEqUQRH7XWjSbNE1nzSHIKFFV1NotT4J\nLbqg0F1o1Ykx7ygG0TWfNIdQjVjzjmIQXVCA5hCqEGveUQyiaz5JNdq0jtNuRVlTSPmaNgtdJAVF\nizVpFrpIaj6JpAR7PoWZXQPeDHLwYswB74QuRIGadj6fcfeb87wxWPPJ3feEOnYRzGy5Tk9rmqSJ\n55P3vWo+iaQoKERSFBT5nQpdgILpfEaCdbRFYqWaQiRFQSGSoqCYwMwOmdlrZnbJzB4Zs92tZrZm\nZoerLN9uZTkfM+uZ2ctmdtHMXqi6jLsx6XzM7ENm9kszuzA6nwcm7tTd9bXDFzAD/B34BDALXAAO\n7LDd74FzwOHQ5Z7mfIAPA38F9o1efyx0uac8nx8CT4x+3gP8C5gdt1/VFOPdBlxy98vuvgqcBe7e\nZruHgWeAt6ssXA5Zzude4Fl3/weAu8d8TlnOx4GbzcyAD5IExdq4nSooxtsLrGx5fXX0u01mthe4\nBzhZYbnymng+wKeBj5jZwMzOm9l9lZVu97Kcz0+AzwH/BF4BfuDu18ftVFmy03sSOOru15OLUe3d\nBHwFOAi8Hxia2Uvu/nrYYuX2TeBl4BvAJ4HfmdmL7v6fnd6goBjvLWB+y+tbRr/bqgOcHQXEHHCX\nma25+3PVFHFXspzPVeBdd38PeM/M/gB8GYgxKLKczwPA4550Ki6Z2RvAZ4E/7bjX0J2lmL9ILhqX\ngf3c6Mh9fsz2Z4i7oz3xfEiaGkujbT8AvAp8IXTZpzifk0B/9PPHR0EzN26/qinGcPc1M3sIeJ5k\npONpd79oZg+O/v5U0ALuUpbzcfe/mdlvgL8A14HT7v5quFLvLOP/zyJwxsxeAYykqTs2RV5pHiIp\nGn0SSVFQiKQoKERSFBQiKQoKkRQFhUiKgkIk5X/rtL7/JgYqZwAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x9ad34e0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "k_means(dataset, k=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
